﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Small.Html.Options;

namespace Small.Html.UI
{
  public static  class HtmlSeach
    {
      /// <summary>
      /// 搜索按钮
      /// </summary>
      /// <param name="helper"></param>
        /// <param name="condictionContainerId">CondictionBegin的Id</param>
      /// <param name="callBack">回调函数,返回获取到的搜索条件function fn(value)</param>
      /// <param name="options"></param>
      /// <returns></returns>
     public static MvcHtmlString Search(this HtmlHelper helper, string condictionContainerId,
         string callBack,SearchOptions  options=null) 
      {
          return new  MvcHtmlString(GenerateHtml(condictionContainerId,callBack, options));
      }

     private static string GenerateHtml(string condictionContainerId,string callBack,SearchOptions options) 
      {
          StringBuilder builder = new StringBuilder();
          if (options == null) 
          {
              options = new SearchOptions();
          }

          string btnSearch = "</div><div class=\"small_predicate_right\"><span class=\"" + options.Class + "\" onclick=\"" + callBack + "(" + "getPredicate('" + condictionContainerId + "'))\">" + options.Text + "</div></span>";

        builder.Append(btnSearch);
          return builder.ToString();
      }
    }
}
